package cn.okcode.slowjson;

import cn.okcode.slowjson.internal.TypeCastUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * json数组的java定义类型
 *
 * @author pyk13
 */
public final class JsonArray extends ArrayList<Object> implements Serializable {

    public JsonArray() {
        super();
    }

    public JsonArray(int initialCapacity) {
        super(initialCapacity);
    }

    public <T> List<T> castToList(Class<T> clazz) {
        List<T> values = new ArrayList<>(super.size());

        for (Object value : this) {
            values.add(TypeCastUtils.castTo(value, clazz));
        }
        return values;
    }
}
